package spec.dengyuru.unit2.task2_4;
import java.util.Scanner;
public class MultiUserRentCal {
    public double[][]initMultiUserRentCal(){
        System.out.println("请输入用户数量");
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        double[][]usersRent=new double[1][n];
        return usersRent;
    }
    public String[]initMultiUserName(double[][]usersRent){
        int len=usersRent[0].length;
        String[]userNames=new String[len];
        Scanner sc=new Scanner(System.in);
        for(int i=0;i<userNames.length;i++){
            System.out.println("请输入第"+(i+1)+"个用户名：");
            String userName=sc.next();
            userNames[i]=userName;
        }
        return userNames;
    }
    public double calculateTotalRent(){
        double totalRent = 0;
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入租金：");
        double monthRent=sc.nextDouble();
        System.out.println("请输入租房时间（以月为单位）：");
        int month=sc.nextInt();
        System.out.println("请输入物业费用：");
        double propertyCost=sc.nextDouble();
        System.out.println("请输入其他费用：");
        double otherCost=sc.nextDouble();
        totalRent+=monthRent*month;
        totalRent+=propertyCost*month;
        totalRent+=otherCost;
        return totalRent;
    }
    public double[][]calCulMultiUserRent(double[][]usersRent){
        for(int i=0;i<usersRent.length;i++) {
            for (int j = 0; j < usersRent[i].length; j++) {
                System.out.println("请输入第" + (j + 1) + "个用户租金：");
                usersRent[i][j] = this.calculateTotalRent();
            }
        }
        return usersRent;
    }
    public void showMultiUserRent(String[]userNames,double[][]usersRent){
        int len=userNames.length;
        for(int i=0;i<len;i++){
            System.out.print(userNames[i]+"          ");
        }
        System.out.println("");
        for(int j=0;j<len;j++){
            System.out.print(usersRent[0][j]+"    |       ");
        }
        System.out.println("");
    }
    public static void main(String[]args){
        MultiUserRentCal multiUserRentCal=new MultiUserRentCal();
        System.out.println("欢迎您使用房屋租赁（多用户）租金计算工具");
        double[][]usersRent=multiUserRentCal.initMultiUserRentCal();
        String[]userNames=multiUserRentCal.initMultiUserName(usersRent);
        usersRent=multiUserRentCal.calCulMultiUserRent(usersRent);
        multiUserRentCal.showMultiUserRent(userNames,usersRent);
    }
}
